package cn.hxth.dubbo.customer.request;

import cn.hxth.api.model.ProductBaseInfo;
import cn.hxth.api.request.Request;
import cn.hxth.api.service.IProductBaseInfoService;

/**
 * 重新加载商品库存的缓存
 * @author Administrator
 *
 */
public class ProductBaseInfoCacheRefreshRequest extends Request {

	/**
	 * 商品id
	 */
	private long pid;
	/**
	 * 商品库存Service
	 */

	private IProductBaseInfoService productBaseInfoService;
	/**
	 * 是否强制刷新缓存
	 */
	private boolean forceRefresh;
	
	public ProductBaseInfoCacheRefreshRequest(long pid,
			IProductBaseInfoService productBaseInfoService,
			boolean forceRefresh) {
		this.pid = pid;
		this.productBaseInfoService = productBaseInfoService;
		this.forceRefresh = forceRefresh;
	}

	public ProductBaseInfoCacheRefreshRequest() {
	}

	@Override
	public void process() {
		// 从数据库中查询最新的商品库存数量
		ProductBaseInfo productBaseInfo = productBaseInfoService.getProductBaseInfo(pid);
		System.out.println("===========日志===========: 已查询到商品最新的库存数量，商品id=" + pid + ", 商品库存数量=" + productBaseInfo.getInventory());
		// 将最新的商品库存数量，刷新到redis缓存中去
		productBaseInfoService.setProductBaseInfoCache(productBaseInfo);
	}
	
	public long getPid() {
		return pid;
	}

	public boolean isForceRefresh() {
		return forceRefresh;
	}
	
}
